home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / test-acceptor.c < prev    next >
C/C++ Source or Header  |  1997-06-13  |  2KB  |  79 lines

  1. /* test-acceptor.c: Test a unix-to-unix connection
  2.  *
  3.  * This is free software, licensed under the GNU Public License V2.
  4.  * See the file COPYING for details.
  5.  */
  6.  
  7. /* "Server" and "client" are fuzzy concepts with the Pilot. The Pilot
  8.  * initiates conversation, and the desktop sits passively and listens, so by
  9.  * unix networking standards at least, the desktop is the server and the
  10.  * Pilot is the client. However, once a connection is established the
  11.  * desktop initiates all further actions while the Pilot sits, passively
  12.  * allowing the desktop to rummage through its databases. Thus the desktop
  13.  * could be called a client.
  14.  *
  15.  * All normal Pilot hot-sync programs should be "acceptors" that sit around
  16.  * waiting for a pilot to connect, using the Unix bind/listen/accept
  17.  * sequence. The test-connector companion to this file is effectively a
  18.  * "fake Pilot" that uses connect to simulate a Pilot connecting. Note that
  19.  * either side can transmit and receive data, as long as they agree on which
  20.  * one is going to be talking.
  21.  *
  22.  * This pair of programs use a pty to simulate the first stages of a Pilot
  23.  * communcation -- CMP exchanges, and baud rate matching. Note that a pty is
  24.  * used to let the two programs talk together, and that no attempt has been
  25.  * made to properly allocate a pty.
  26.  *
  27.  * Also note that dlp_AbortSync is used, instead of EndOfSync. That is
  28.  * because the normal EndOfSync proceedings involves sending a padp packet,
  29.  * which would not work as neither side is expecting such a packet.
  30.  *
  31.  */ 
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include "pi-source.h"
  36. #include "pi-socket.h"
  37. #include "pi-dlp.h"
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.   struct pi_sockaddr addr;
  42.   int sd;
  43.   char buffer[64];
  44.   int ret;
  45.  
  46.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  47.     perror("pi_socket");
  48.     exit(1);
  49.   }
  50.     
  51.   addr.pi_family = PI_AF_SLP;
  52.   strcpy(addr.pi_device,"/dev/ptyp9"); /* Bogus PTY allocation */
  53.   
  54.   ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
  55.   if(ret == -1) {
  56.     perror("pi_bind");
  57.     exit(1);
  58.   }
  59.  
  60.   ret = pi_listen(sd, 1);
  61.   if(ret == -1) {
  62.     perror("pi_listen");
  63.     exit(1);
  64.   }
  65.  
  66.   sd = pi_accept(sd, 0, 0);
  67.   if(sd < 0) {
  68.     perror("pi_accept");
  69.     exit(1);
  70.   }
  71.   
  72.   pi_write(sd, "Sent from server", 17 );
  73.   pi_read(sd, buffer, 64);
  74.   puts(buffer);
  75.   
  76.   dlp_AbortSync(sd);
  77.   exit(0);
  78. }
  79.